<template>
  <div class="detail-container">
    <h3>运动管理详情</h3>
    <el-card class="detail-card">
      <div class="detail-item">
        <label>运动类型:</label>
        <span>{{ detail.exerciseType }}</span>
      </div>
      <div class="detail-item">
        <label>运动计划:</label>
        <span>{{ detail.plan }}</span>
      </div>
      <div class="detail-item">
        <label>运动记录:</label>
        <span>{{ detail.record }}</span>
      </div>
      <div class="detail-item">
        <label>记录时间:</label>
        <span>{{ formatDate(detail.createTime) }}</span>
      </div>
      <div class="detail-footer">
        <el-button type="primary" @click="goBack">返回</el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getExerciseDetailApi } from '../api/exercise'
import { ElMessage } from 'element-plus'

const route = useRoute()
const router = useRouter()
const detail = ref({})

const formatDate = (date) => {
  return new Date(date).toLocaleString()
}

const goBack = () => {
  router.back()
}

onMounted(async () => {
  const id = route.params.id
  if (id) {
    try {
      const res = await getExerciseDetailApi(id)
      detail.value = res.data
    } catch (error) {
      ElMessage.error('获取详情失败')
    }
  }
})
</script>

<style scoped>
.detail-container {
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
}

.detail-card {
  margin-top: 20px;
}

.detail-item {
  margin-bottom: 15px;
  display: flex;
  align-items: baseline;
}

.detail-item label {
  font-weight: bold;
  margin-right: 10px;
  color: #606266;
  min-width: 80px;
}

.detail-item span {
  color: #303133;
  flex: 1;
}

.detail-footer {
  margin-top: 20px;
  text-align: right;
}
</style> 